
package com.ps.helpdesk.persistence;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class ManagerConnection {

	private final EntityManagerFactory factory;

	private final EntityManager manager;

	private static ManagerConnection instance;
	
	public static String DATA_BASE = null;

	private ManagerConnection() {

		factory = Persistence.createEntityManagerFactory( DATA_BASE );
		manager = factory.createEntityManager();
	}

	public void close() {

		manager.close();
		factory.close();
	}

	public static ManagerConnection getInstance() {

		if ( instance == null ) {
			instance = new ManagerConnection();
		}
		return instance;
	}

	public EntityManagerFactory getFactory() {

		return factory;
	}

	public EntityManager getManager() {

		return manager;
	}

}
